package com.多米诺;

import java.util.Arrays;

class Solution {
	public static void main(String[] args) {
		String s = ".......L.L";
		Solution s1 = new Solution();
		String end = s1.pushDominoes(s);
		System.out.println(end);
	}

	public String pushDominoes(String dominoes) {
		char temp[] = dominoes.toCharArray();
		if (temp.length == 1)
			return new String(temp);
		char change[] = new char[temp.length];
		change = copy(temp, change);
		// 第一次变换
		for (int i = 0; i < temp.length; i++) {
			if (temp[i] == '.') {
				if (i == 0) {
					if (temp[i + 1] == 'L')
						change[i] = 'L';
				} else if (i == temp.length - 1) {
					if (temp[i - 1] == 'R')
						change[i] = 'R';
				} else {
					if ((temp[i - 1] == 'R' && temp[i + 1] == '.') || (temp[i - 1] == 'R' && temp[i + 1] == 'R')) {
						change[i] = 'R';
					}
					if ((temp[i + 1] == 'L' && temp[i - 1] == '.') || (temp[i + 1] == 'L' && temp[i - 1] == 'L'))
						change[i] = 'L';
				}
			}
		}
		System.out.println(Arrays.toString(change));
		System.out.println(ischange(temp, change));
		while (ischange(temp, change)) {
			temp = change;
			 change = new char[temp.length];
			change = copy(temp, change);
			for (int i = 0; i < temp.length; i++) {
				if (temp[i] == '.') {
					if (i == 0) {
						if (temp[i + 1] == 'L')
							change[i] = 'L';
					} else if (i == temp.length - 1) {
						if (temp[i - 1] == 'R')
							change[i] = 'R';
					} else {
						if ((temp[i - 1] == 'R' && temp[i + 1] == '.') || (temp[i - 1] == 'R' && temp[i + 1] == 'R')) {
							change[i] = 'R';
						}
						if ((temp[i + 1] == 'L' && temp[i - 1] == '.') || (temp[i + 1] == 'L' && temp[i - 1] == 'L'))
							change[i] = 'L';
					}
				}
			}
		}
		return new String(temp);

	}

	public boolean ischange(char temp1[], char temp2[]) {
		int len = temp1.length;
		for (int i = 0; i < len; i++) {
			if (temp1[i] != temp2[i]) {
				return true;
			}
		}
		return false;
	}

	public char[] copy(char[] temp, char change[]) {
		int len = temp.length;
		for (int i = 0; i < len; i++) {
			change[i] = temp[i];
		}
		return change;
	}
}
